import { Button as AntButton, ButtonProps } from 'antd';
import { useState } from 'react';

export type Props = Omit<ButtonProps & React.RefAttributes<HTMLElement>, 'loading'>;

export default function Button({ children, type = 'primary', onClick, ...props }: Props) {
	const [loading, setloading] = useState(false);
	return <AntButton loading={loading} type='primary' onClick={async (e) => {
		try {
			setloading(true);
			onClick && await onClick(e);
		} catch (error) {
			console.error(error);
		} finally {
			setloading(false);
		}
	}} >{children}</AntButton>;
}
